package com.ugoodtech.mdcc.core.utils;


import org.apache.commons.lang3.StringUtils;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class FieldArrayUtil {

    public static <T>String getFieldStr(Collection<T> dataList, String fieldName) {
        List<String> stringList=new ArrayList<>();
        try {
            for(T data:dataList){
               Class c= data.getClass();
               String getMethod=ModelUtil.getGetMethod(fieldName);
                Method add = c.getDeclaredMethod(getMethod);
                add.setAccessible(true);
                Object o =add.invoke(data);
                String fieldValue=null;
                if(null!=o){
                    fieldValue=o.toString();
                }
                if(null!=fieldValue){
                    stringList.add(fieldValue.toString());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
        return StringUtils.join(stringList,",");
    }





}
